﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class page_ExcelInput : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }

    /// <summary>
    /// 上传Excel文件并将数据导入到SqlServer中;
    /// </summary>
    protected void btStartInput_Click(object sender, EventArgs e)
    {
        string File = this.FileUpload.FileName;

        if (File == "")
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "请选择您要导入的文件!");
            return;
        }

        string[] files = new string[2];
        files = File.Split('.');

        if (!files[1].Equals("xls"))
        {
            ShoveEL._Web.JavaScript.Alert(this.Page, "文件格式不对，请选择Excel文件!");
            return;
        }

        string Path = Server.MapPath("~/UpFiles/Excel/") + FileUpload.FileName;

        try
        {
            this.FileUpload.SaveAs(Path);

            //文件上传成功，开始执行数据导入的方法
            DataSet ds = new DataSet();
            ds = DataTableToExcel.ExcelToDataSet(Path);

            DataTableToExcel.DataSetToSqlServer(ds, "T_Goods","");

            ShoveEL._Web.JavaScript.Alert(this.Page, "注册卡导入成功！");
            Response.Write("<script>window.close();</script>");
        }
        catch { }
    }

}
